﻿using System;
using System.Data;
using System.Text;
using System.Web;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using AnyOffice.Components;
using AnyOffice.DAL;
using AnyOffice.Model;
namespace AnyOffice.general.system.workflow.flow_type
{
    public partial class type_new : ModulePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.Page.IsPostBack)
            {
                DataTable table = new FlowSortDao().SelectAll(base.Conn);
                this.ddlSortId.DataSource = table;
                this.ddlSortId.DataValueField = "SortId";
                this.ddlSortId.DataTextField = "SortName";
                this.ddlSortId.DataBind();
                DataTable table2 = new FlowFormTypeDao().SelectAll(base.Conn);
                this.ddlFormId.DataSource = table2;
                this.ddlFormId.DataValueField = "FormId";
                this.ddlFormId.DataTextField = "FormName";
                this.ddlFormId.DataBind();
            }
            if (this.Page.IsPostBack)
            {
                FlowTypeDao dao3 = new FlowTypeDao();
                FlowTypeData data = new FlowTypeData();
                data.FlowSort = Convert.ToInt32(this.ddlSortId.SelectedValue);
                data.FlowNo = Convert.ToInt32(this.txtFlowNo.Text);
                data.FlowName = this.txtFlowName.Text;
                data.FlowType = Convert.ToInt32(this.ddlFlowType.SelectedValue);
                data.FormId = Convert.ToInt32(this.ddlFormId.SelectedValue);
                data.FlowDoc = Convert.ToBoolean(this.ddlFlowDoc.SelectedValue);
                if (this.txtFlowDesc.Text != string.Empty)
                {
                    data.FlowDesc = this.txtFlowDesc.Text;
                }
                if (this.txtAutoName.Text != string.Empty)
                {
                    data.AutoName = this.txtAutoName.Text;
                }
                data.AutoNum = Convert.ToInt32(this.txtAutoNum.Text);
                data.AutoLen = Convert.ToInt32(this.txtAutoLen.Text);
                data.AutoEdit = Convert.ToInt32(this.ddlAutoEdit.SelectedValue);
                dao3.Insert(base.Conn, data);
                StringBuilder builder = new StringBuilder("<script>\n");
                builder.Append("parent.sort.location.reload();\n");
                builder.Append("location = 'type_list.aspx?sort_id=" + this.ddlSortId.SelectedValue + "';\n");
                builder.Append("</script>\n");
                if (!this.Page.IsClientScriptBlockRegistered("flow_type"))
                {
                    this.Page.RegisterClientScriptBlock("flow_type", builder.ToString());
                }
            }

        }
    }
}
